home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / filesy~1 / mfsdefrg.zoo / README < prev    next >
Encoding:
Text File  |  1993-01-07  |  12.0 KB  |  289 lines

  1. README for the Linus extended file system defragmenter
  2.  
  3. edefrag emergency release 0.3b alpha
  4.  
  5. Copyright Stephen C. Tweedie, 1992, 1993 (sct@dcs.ed.ac.uk)
  6.  
  7.     Parts Copyright Remy Card, 1992 (card@masi.ibp.fr)
  8.     Parts Copyright Linus Torvalds, 1992 (torvalds@kruuna.helsinki.fi)
  9.  
  10. This file and the accompanying program may be redistributed under the
  11. terms of the GNU General Public License.
  12.  
  13.  
  14. INTRODUCTION: What does it do?
  15. ==============================
  16.  
  17. As a file system is used, data tends to become more and more scattered
  18. over the disk, degrading performance.  A disk defragmenter simply
  19. reorganises the data on the disk, so that individual files occupy a
  20. single sequential set of disk blocks, and all the free space on the
  21. disk is collected together in a single region.  This generally means
  22. that reading a whole file is more efficient.
  23.  
  24. The extended file system stores a list of unused disk blocks in a
  25. series of unused blocks scattered over the disk (the "free list").
  26. When blocks are required to store data, they are removed from the head
  27. of the list, and are added back when released (by unlinking or
  28. truncating a file).
  29.  
  30. However, only the free blocks stored at the head of the list are
  31. available to the extfs at any time.  This means that not all the free
  32. space is known to the extfs when it tries to find a free block; as a
  33. result, it does not always find the most efficient way to use free
  34. space.
  35.  
  36. This is in contrast to the minix file system, in which free space is
  37. stored in a single bitmap, and the file system can allocate free space
  38. from anywhere on the disk.
  39.  
  40. The resulting poorer performance over time of the extended file system
  41. is unfortunate, because the larger partitions and longer filenames it
  42. supports are useful to have around.
  43.  
  44. So, here is the extended file system defragmenter - recover all that
  45. lost performance from your extfs partition.
  46.  
  47. For an idea of the performance gains you might obtain - the first time
  48. I defragmented my file system, the time taken to boot my PC (from
  49. switching on until the XDM X windows login prompt stabilises) dropped
  50. from 37 seconds to 27 seconds.
  51.  
  52. As for the performance of the defragmenter itself - well, that first
  53. version worked, but it thrashed my hard disk solid for over an hour
  54. (this was for a 90MB partition).  The current version runs in not much
  55. over 5 minutes now, and most of the accesses are sequential (ie. NO
  56. thrashing).  Granted that the fragmentation is not severe any longer,
  57. but that 5 or 6 minutes does still include reading and writing over
  58. 70MB of the partition.
  59.  
  60. Note - as of release 0.3, minix file systems are also supported.
  61.  
  62. HOW TO USE: and a few warnings.
  63. ===============================
  64.  
  65. Number one - (this applies to all - repeat, ALL - major file system
  66.               operations).
  67.  
  68. *** BACK UP ANY IMPORTANT DATA BEFORE YOU START. ***
  69.  
  70. There may be bugs in the defragmenter.  You may have undetected errors
  71. on your disk which are undiscovered until edefrag tries to write to a
  72. bad block which has never been accessed before.  There may be power
  73. glitches, memory glitches, kernel errors.  [e]defrag does some major
  74. reorganisation of disk data, and if for any reason it doesn't finish
  75. its work, most of your file system is likely to be trashed.
  76.  
  77. *** YOU HAVE BEEN WARNED. ***
  78.  
  79. *** NEVER try to defragment an active or mounted file system.
  80.  
  81. It is often safe to use [e]fsck on a mounted fs; don't be conned into
  82. thinking that the same will work for [e]defrag.  The file system will
  83. be totally unusable while [e]defrag is working; and if this causes a
  84. kernel crash, or if the fs interferes with the defragmenter as it
  85. runs, you may well loose your entire partition.
  86.  
  87. This means that in order to defragment a root partition, you will
  88. probably need to run [e]defrag from a boot floppy.  
  89.  
  90. However, it IS totally safe to run [e]defrag in its readonly mode (for
  91. testing) on an active partition.
  92.  
  93. *** Run [e]fsck on the partition first, to check its integrity.
  94.  
  95. Although I have been quite careful about the defragmenter's behaviour
  96. on a corrupt file system (it should back down gracefully before doing
  97. anything irreversible), it may well cause a lot of damage if the file
  98. system is invalid in any way.
  99.  
  100. In particular, there is currently no handling of read/write errors in
  101. the defragmenter.  The extfs version DOES understand the bad block
  102. inode (and the special handling now works - as of version 0.3b), so if
  103. you suspect you might have bad blocks, try running efsck -t (test for
  104. bad blocks) before defragmenting.
  105.  
  106. However, if you have an IDE drive, you needn't worry; you should never
  107. get any hd errors, as IDE drives dynamically remap bad blocks
  108. internally, as they occur.  Until I have proper bad block support for
  109. minix, it's probably unwise to try to defragment a suspect, non-IDE
  110. minix partition.
  111.  
  112. *** Run [e]defrag -r next, just to be sure.
  113.  
  114. If there are any bugs in the defragmenter, running in readonly mode
  115. first may find them ([e]defrag does quite a lot of self-checking as it
  116. goes) before you lose any data.
  117.  
  118. *** Reinstall lilo after defragmenting a bootable partition.
  119.  
  120. Defragmentation moves data around the disk.  edefrag knows all of the
  121. file system's internal pointers to this data, so these are adjusted as
  122. needed to keep the file system intact.  Lilo, unfortunately, keeps its
  123. own pointers to the location of kernel image files, so that the kernel
  124. can be loaded before the filing system is running.  (These pointers
  125. are usually kept in /etc/lilo/map.)  If you defragment a partition
  126. containing a lilo-bootable kernel image, you MUST reinstall lilo to
  127. rebuild the now-invalid map file.
  128.  
  129.  
  130. Usage: edefrag [-Vdrsv] [-p pool_size] /dev/name
  131.  
  132.     -V : Prints the full CVS version id for the release.  Send me
  133.          this information with any problem reports or suggestions.
  134.     -s : Show superblock information.
  135.     -v : Verbose.  Shows what the program is doing.  If used
  136.          twice, gives extra progress information.
  137.     -r : Readonly.  This opens the file system in readonly mode,
  138.          which guarantees that your data will not be harmed.  This
  139.          can be useful for testing purposes, especially for
  140.          working out the best buffer pool size to use.
  141.     -d : (If enabled at compile-time) Debug mode.
  142.  
  143.     The pool_size is the number of 1KB (disk block) buffers to
  144.     allocate to the buffer pool while relocating the file system
  145.     data. (Default is 512; it cannot be set below 20.)
  146.  
  147.     Finally, /dev/name should be the device to be defragmented; an
  148.     image file may also be used (for debugging purposes), as
  149.     edefrag does not check that the file is a block device.
  150.  
  151.  
  152. HINTS
  153. =====
  154.  
  155. You may want to experiment with edefrag to find the best memory usage
  156. before defragmenting.  Currently, the significant tables held in
  157. memory by edefrag are:
  158.  
  159. Relocation maps - eight bytes per block.
  160. Inode table - 64 bytes per inode.
  161. Inode maps - 8 bytes per inode.
  162.  
  163. The buffer pool must be added on top of this.
  164.  
  165. For a typical file system, this works out at around 26K of memory
  166. required per MB of disk space, or 2.6MB memory for a 100MB disk
  167. partition; plus the buffer pool.
  168.  
  169. It is safe to use a swap file or partition if memory is tight (but NOT
  170. one on the file system being defragmented!); this may not even affect
  171. performance much, since during its first (mapping) phase, the
  172. defragmenter accesses the inode table but not the buffer pool; during
  173. the second (relocating) phase, the inode table is unused and the
  174. buffer pool comes into play.
  175.  
  176. (Don't worry about the defragmenter suddenly running out of memory
  177. during its work; all the memory required is allocated and initialised
  178. before it starts operation, so any memory errors should occur before
  179. the file system gets touched.)
  180.  
  181. The defragmenter tries as hard as possible to group reads and writes
  182. into long sequential accesses.  Data being overwritten on the disk
  183. gets put into a rescue buffer, and may soon just get written back
  184. during the normal course of sequential writes.  However, if the buffer
  185. pool is too small or the disk is highly fragmented, edefrag tries to
  186. clear out the rescued data by seeing if its final destination is empty
  187. yet.  (These are termed "migrate" writes; the data migrates from the
  188. rescue pool to the output pool.)  If that fails to free enough space,
  189. edefrag forces some of the rescue buffers out into empty blocks
  190. ("forcing" writes), from which the data will have to be re-read at
  191. some point.
  192.  
  193. The upshot of this is that normal buffer writes are highly sequential
  194. and efficient; "migrate" writes are slightly less sequential, but
  195. still quite efficient; and "forcing" writes cause data to be read
  196. twice, and from this point of view are quite inefficient.
  197.  
  198. Running edefrag with the -r option will scan your file system
  199. non-destructively, and will report on the work it would have to do to
  200. defragment the disk.  This facility can be used to adjust the pool
  201. size requested to compromise between memory used and defragmenting
  202. efficiency.
  203.  
  204. For example, I have just run:
  205. $ edefrag -r /dev/hda3        [ default 512K buffer pool ]
  206.  
  207. [ ... superblock statistics deleted ... ]
  208. Relocation statistics:
  209. 44807 buffer reads in 91 groups, of which:
  210.   14004 read-aheads.
  211. 44807 buffer writes in 91 groups, of which:
  212.   0 migrations, 0 forces.
  213.  
  214. $ edefrag -r -p 100 /dev/hda3
  215.  
  216. [ ... superblock statistics deleted ... ]
  217. 45299 buffer reads in 618 groups, of which:
  218.   13310 read-aheads.
  219. 45299 buffer writes in 618 groups, of which:
  220.   202 migrations, 492 forces.
  221.  
  222. The first result indicates a higher efficiency with 512 buffers
  223. than with 100.  However, even the second run would have been quite
  224. quick; 492 forces out of a 90MB file system is not bad.  (By the way,
  225. the reason the total number of writes is less than 90MB is that much
  226. of my hard disk was fully defragmented anyway. 8-)  
  227.  
  228. If, however, my disk had been badly fragmented (as it used to be...) I
  229. would probably have had to allocate around 2000-4000 buffers to get
  230. good efficiency with few forced writes.
  231.  
  232. The tradeoff is that the less memory you allocate for pool buffers,
  233. the more is available for the kernel to cache reads itself.  Since the
  234. kernel reads entire tracks at a time, leaving space to the kernel
  235. effectively gives extra "free" buffer reads.
  236.  
  237. I'm not yet quite sure whether it is more efficient to leave the
  238. kernel with a healthily large cache for itself, or to allocate as much
  239. for edefrag's own (more optimised for the task) buffering scheme.  You
  240. may want to experiment here, and I would be interested in hearing any
  241. conclusions you reach.  I am running with 16MB ram, so if you have
  242. less ram your mileage may vary. 
  243.  
  244.  
  245. WARRANTY:
  246. =========
  247.  
  248. NONE.  Use at your own risk.  BACK UP ANY IMPORTANT DATA BEFORE YOU
  249. START.
  250.  
  251. I have successfully run edefrag on my own root, 90MB extfs partition
  252. at home.  It has been tested on particularly hard jobs, such as
  253. defragmenting a 1.44MB floppy with a buffer pool restricted to 20KB -
  254. lots of extra writes are necessary to cope with a tiny buffer pool.
  255. This release has never crashed for me, and has never lost me any data.
  256. I am confident enough to use it fairly regularly, and if I back up
  257. data before using it, I only backup stuff which cannot be reinstalled
  258. from other sources.  I have tried as far as possible to ensure that
  259. edefrag will not harm your data.  However, I cannot make ANY guarantee
  260. that it won't.  Use it and enjoy it, but don't blame me if it ruins
  261. your day.
  262.  
  263. Having said that, if you DO have problems, let me know and I'll try to
  264. fix them for the next release.  (Even better, send me bug fixes!)
  265.  
  266.  
  267. TO DO:
  268. ======
  269.  
  270. There is currently NO minix file system support.  Watch this space.
  271. When the mark 2 extfs is released by Remy Card, I should support
  272. that, too.
  273.  
  274. I currently read in the entire inode table before starting, and write
  275. it out again at the end.  This is really a throw-back to edefrag's
  276. origins in efsck.  Since I no longer access the inodes at all after
  277. initially calculating the disk relocation maps, I could probably get
  278. away with just accessing inode data as needed, so using less memory.
  279. Otherwise, try sharing memory between the inode table and the buffer
  280. pool, since the two are never used at the same time.
  281.  
  282. The verbose (-v) option could do with a little rationalisation, and an
  283. interactive (maybe full screen?) mode showing progress would be nice.
  284.  
  285. The sync() frequency should probably be configurable at run-time.
  286.  
  287. ===
  288. Stephen Tweedie (sct@dcs.ed.ac.uk).
  289.